package com.test.util.datasource;

import com.test.bean.BaseConnectionInfo;

import java.util.*;

/**
 * 项目数据库管理。提供根据项目编码查询数据库名称和IP的接口。
 * @Description
 * @auther Lelouch
 * @create 2018-12-26  10:43
 */
public class ProjectDBMgr {

    private static ProjectDBMgr projectDBMgr;
    private static Map<String, BaseConnectionInfo> connMap = new HashMap<>();

    public static ProjectDBMgr getInstance(String dataBaseCode, BaseConnectionInfo info) {
        if(projectDBMgr == null) {
            synchronized (ProjectDBMgr.class) {
                if(projectDBMgr == null) {
                    projectDBMgr = new ProjectDBMgr();
                }
            }
        }
        if(null != dataBaseCode && null != info) {
            connMap.put(dataBaseCode, info);
        }
        return projectDBMgr;
    }

    public static BaseConnectionInfo getConnectionInfo(String projectCode) {
        if (connMap.containsKey(projectCode)) {
            return connMap.get(projectCode);
        }
        return null;
    }
}
